package com.ys.controller.web.sys;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.entity.hr.ThrOperateCompanyApply;
import com.ys.entity.sys.TsOperateOrg;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;

@Controller
@RequestMapping("/web/sys/tsOperateOrg")
public class WebTsOperateOrgController {
	
	@Autowired
	private CommonApiService<TsOperateOrg> commonApiService;
	
	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response,
			Long pid){
		
		if (pid == null) {
			return W.error(model, "上级ID不能为空");
		}

		try {
			
			return commonApiService.toAdd(model, new TsOperateOrg().setPid(pid), MenuId.TS_OperateOrg, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/**
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model,
			Long id){
		
		TsOperateOrg entity = new TsOperateOrg().setId(id).queryFirst();
		String headVgsbm = entity.getHeadVgsbm();
		Map<String, Object> extraParam = new HashMap<String, Object>();
		if (headVgsbm != null && headVgsbm.length() > 0) {
			ThrOperateCompanyApply apply = new ThrOperateCompanyApply().setVgsbm(headVgsbm).queryFirst();
			extraParam.put("headVgsjc", apply.getVgsjc());
		}
		
		
		
		try {
			return commonApiService.toEdit(model, id, new TsOperateOrg(), MenuId.TS_OperateOrg, extraParam, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
}
